
// request库的上层封装，支持await，直接调用,可以向豆瓣API的服务端发起请求
const rp = require('request-promise-native')	

async function fetchMovie(item){
	const url = `http://api.douban.com/v2/movie/subject/${item.doubanId}`

	const res = await rp(url)

	return res
}

;(async () => {
	let movies = [
	{ 
		doubanId: 2131459,
	    title: '机器人总动员',
	    rate: 9.3,
	    poster: 'https://img3.doubanio.com/view/photo/l_ratio_poster/public/p1461851991.jpg' 
	},
  	{ 
  		doubanId: 4920528,
	    title: '那些年，我们一起追的女孩',
	    rate: 8.1,
	    poster: 'https://img3.doubanio.com/view/photo/l_ratio_poster/public/p1062824805.jpg' 
	} 
  	]

  	//遍历这个数组
  	movies.map( async movies => {
  		let movieData = await fetchMovie(movies)

  		// 通过 jsonparse 解析 movieData 
  		try{
  			movieData = JSON.parse(movieData)
  			console.log(movieData.tags)
  			console.log(movieData.summary)
  		}catch (err){
  			console.log(err)
  		}

  		// console.log(movieData)
  	})

})()